<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/22
 * Time: 17:34
 */

namespace app\home\controller\Cloud;
use think\Controller;

class Base extends Controller {

    public $mapKey = "fdd58cecdbc8cafcf301139e280eaed4";


    public function get_https_data($url)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        $data = curl_exec($curl);
        curl_close($curl);
        return $data;
    }

    //获取经纬度
    public function getLocal($address)
    {
        $key = $this->mapKey;
        $url = "http://restapi.amap.com/v3/geocode/geo?address=$address&output=json&key=$key";
        $res = $this->get_https_data($url);
        $result = json_decode($res, true);
        return $result;
    }
    public function return_local($address)
    {
        return $this->getLocal($address);

    }

    //经纬度转数组
    public function getAddress($lng,$lat)
    {
        $url = 'http://restapi.amap.com/v3/geocode/regeo?key='.$this->mapKey.'&location='.$lng.','.$lat;
        $res = $this->get_https_data($url);
        return $res;
    }
}
